import {
	RouterMount,
	createRouter
} from 'uni-simple-router';
import store from '../store'
import ROUTES from './modules'
import {
	showCancelModule
} from "../utils/message"

const router = createRouter({
	platform: process.env.VUE_APP_PLATFORM,
	routes: [...ROUTES]
});

//全局路由前置守卫
router.beforeEach((to, from, next) => {
	// next()
	const {
		requiresAuth
	} = to.meta
	if (requiresAuth) {
		const {
			getUserLoginState
		} = store.getters
		if (getUserLoginState) {
			next()
		} else {
			showCancelModule("用户未登录，是否进行登录",
				() => {
					next({
						path: '/pages/login/login'
					})
				},
				() => {
					/* 点击取消则不进行跳转 */
					next(false)
				}
			)
		}
	} else {
		next()
	}

});
// 全局路由后置守卫
router.afterEach((to, from) => {
	// console.log('跳转结束')
})

export {
	router,
	RouterMount
}
